/**
 ****************************************************************************************************
 * @file        esp_2d_draw.h
 * @author      嵌入式小书虫
 * @version     V1.0
 * @date        2020-04-17
 * @brief       esp_2d绘制函数
 ****************************************************************************************************
 *
 * 修改说明
 * V1.0 20200417
 * 第一次发布
 <欢迎关注微信公众号：嵌入式小书虫>
 *
 ****************************************************************************************************
 */

#ifndef _ESP_2D_DRAW_H
#define _ESP_2D_DRAW_H


#include "esp_2d.h"

#include<string.h>
#ifndef MAX
#   define MAX(a,b)	((a) > (b) ? (a) : (b))
#endif

#ifndef MIN
#   define MIN(a,b)	((a) < (b) ? (a) : (b))
#endif

/******************************************************************************************/
extern esp_2d_font_tile_t esp_2d_font;


bool esp_2d_is_point_inside_region( const esp_2d_region_t *ptRegion,
                                    const esp_2d_location_t *ptPoint);

bool esp_2d_region_intersect(   const esp_2d_region_t *ptRegionIn0,
                                const esp_2d_region_t *ptRegionIn1,
                                esp_2d_region_t *ptRegionOut);
                                
esp_2d_fsm_rt_t esp_2d_fill_colour( esp_2d_op_t* pt_esp_2d_op,
                                    const esp_2d_region_t * ptRegion,
                                    uint_fast16_t hwColour);

esp_2d_fsm_rt_t esp_2d_rgb565_fill_colour_with_opacity( 
                                                esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_region_t *ptRegion,
                                                uint16_t tColour,
                                                uint_fast8_t chRatio);

esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_only( esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                            const esp_2d_region_t *ptRegion); 
                                                
esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_only_and_fill( esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                            const esp_2d_region_t *ptRegion);                                                
                                                
esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_keing(  esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                                const esp_2d_region_t *ptRegion,
                                                uint16_t color); 
                                                
esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_keing_and_fill( esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                            const esp_2d_region_t *ptRegion,
                                                uint16_t color);                                                

esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_keing_Y_mirror_image(  esp_2d_op_t* pt_esp_2d_op,
                                                               const esp_2d_tile_t *ptSource,                                            
                                                            const esp_2d_region_t *ptRegion,
                                                            uint16_t color); 
esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_keing_X_mirror_image(esp_2d_op_t* pt_esp_2d_op,
                                                            const esp_2d_tile_t *ptSource,                                            
                                                            const esp_2d_region_t *ptRegion,
                                                                uint16_t color);  
esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_keing_XY_mirror_image(esp_2d_op_t* pt_esp_2d_op,
                                            const esp_2d_tile_t *ptSource,                                            
                                            const esp_2d_region_t *ptRegion,
                                                uint16_t color);    
//=============================opacity========================================================================
esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_only_and_opacity(esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                                const esp_2d_region_t *ptRegion,
                                                uint_fast8_t chRatio);  
esp_2d_fsm_rt_t esp_2dp_rgb16_tile_copy_keing_and_opacity(esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                                const esp_2d_region_t *ptRegion,
                                                uint16_t color,
                                                uint_fast8_t chRatio);  
//================mask========================================================================== 
esp_2d_fsm_rt_t esp_2d_fill_colour_with_mask(esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                                const esp_2d_region_t *ptRegion,
                                                uint16_t color);  
                                                
esp_2d_fsm_rt_t esp_2d_fill_colour_with_mask2(esp_2d_op_t* pt_esp_2d_op,const esp_2d_tile_t *ptSource,                                            
                                                const esp_2d_region_t *ptRegion,
                                                uint16_t color);                                                

esp_2d_fsm_rt_t esp_2d_fill_colour_with_mask_and_opacity(esp_2d_op_t* pt_esp_2d_op,
                                                const esp_2d_tile_t *ptSource,                                            
                                                const esp_2d_region_t *ptRegion,
                                                uint16_t color,
                                                uint8_t chRatio);      
//=========================time_out=====================================================================
int64_t esp_2d_helper_get_system_timestamp(void);                                                
void s_tHelper_wMSUnit_init();  
bool esp_2d_helper_is_time_out(int64_t lPeriod, int64_t *plTimestamp);    

void calculate_fps_time(uint8_t type);
uint32_t get_fps_time();                                                
//================draw char========================================================================== 
esp_2d_fsm_rt_t esp_2dp_draw_point(esp_2d_op_t* pt_esp_2d_op,
                                esp_2d_location_t location,
                                uint16_t color); 
esp_2d_fsm_rt_t esp_2dp_draw_point_and_opacity(esp_2d_op_t* pt_esp_2d_op,
                                esp_2d_location_t location,
                                uint16_t color,
                                uint8_t chRatio);                                                
esp_2d_fsm_rt_t esp_2dp_draw_char2(esp_2d_op_t* pt_esp_2d_op, const char ch,                                            
                               const esp_2d_region_t *ptRegion);
esp_2d_fsm_rt_t esp_2dp_draw_char(esp_2d_op_t* pt_esp_2d_op, const char ch,                                            
                               const esp_2d_region_t *ptRegion,
                                   uint16_t color);

extern const esp_2d_font_tile_t esp_2d_FONT_6x8;
extern const esp_2d_font_tile_t esp_2d_FONT_16x24;
int esp_2d_lcd_printf(const char *format, ...);
void esp_2d_lcd_text_location(uint8_t chY, uint8_t chX);
void esp_2d_set_lcd_text_font(esp_2d_font_tile_t font);
void esp_2d_set_lcd_text_color(uint16_t color);                               
#endif
